﻿create procedure [dbo].[usp_TeamFoundationServerInsert]
	@Uri nvarchar(1024)
as

begin try
	
	begin transaction
	
		if not exists(select * from [dbo].[TeamFoundationServer] where [Uri] = @Uri)
			begin
										                              
				insert [dbo].[TeamFoundationServer]
				(
					[Uri]				
			    )
				values
				(
					@Uri
				)
				
				select TeamFoundationServerId, ConcurrencyId, Created, Updated from [dbo].[TeamFoundationServer] where @@rowcount > 0 and TeamFoundationServerId = scope_identity()
			
			end
			
		else
			
			begin
			
				select TeamFoundationServerId, ConcurrencyId, Created, Updated from [dbo].[TeamFoundationServer] where [Uri] = @Uri
			end
	
	commit transaction

end try
	
begin catch
	if @@trancount > 0
	begin
		rollback transaction;
	end
	execute [dbo].[usp_SqlErrorInsert]
end catch


